<?php
    $this->menu=array(
    array('label'=>Yii::t('BackEnd', 'Manage Article'), 'url'=>array('admin')),
    array('label'=>Yii::t('BackEnd', 'Create Article'), 'url'=>array('create')),
    array('label'=>Yii::t('BackEnd', 'Manage Article Category'), 'url'=>array('articlecategory/admin')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#article-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<?= $this->renderPartial('//layouts/sidebar'); ?>

<!-- Begin Content -->
<section>
    <div class="heading_section">
        <span><?= Yii::t('BackEnd','Manage Article'); ?></span>
    </div>
    
    <div class="content">
        <p style="font-weight: bold;"><?= Yii::t('BackEnd', 'Search Article'); ?>:</p>
        <div class="search-form">
        <?php $this->renderPartial('_search',array(
        	'model'=>$model,
        )); ?>
        </div><!-- search-form -->
        
        <div style="clear: both"></div>
        <?php $form = $this->beginWidget('CActiveForm', array(
            'enableAjaxValidation'=>true,
        )); ?>
        
        <?php $this->widget('zii.widgets.grid.CGridView', array(
        	'id'=>'article-grid',
        	'dataProvider'=>$model->search(),
            'emptyText'=>Yii::t('BackEnd','Empty result'),
            'summaryText' => Yii::t('BackEnd','Displaying {end}-{count} of {count} result'),
            'pager' => array(
                'header' => '',
                'prevPageLabel' => Yii::t('BackEnd','Next'),
                'nextPageLabel' => Yii::t('BackEnd','Prev'),
            ),
        	'columns'=>array(
        		'id',
                'title',
                array(
                    'name' => 'image',
                    'type' => 'raw',
                    'value' => 'CHtml::image(Article::model()->getImageArticle($data->image),null,array(\'style\'=>\'width:50px; height:50px\'))',
                    'sortable' => false,
                    'htmlOptions' => array(
                        'style' => 'text-align: center',
                    ),
                ),
        		array(
                    'name'=>'article_category.name',
                ),
        		array(
                    'name'=>'user.fullname',
                ),
        		array(
                    'name'=>'update_time',
                    'value'=>'date("d/m/Y H:i:s", strtotime($data->update_time))',
                ),
        		array(
                    'class' => 'CLinkColumn',
                    'header'=>Yii::t('BackEnd','Is Hot'),
                    'labelExpression' => 'Common::getStatus($data->is_hot)',
                    'urlExpression' => 'Yii::app()->createUrl("article/hot", array("id"=>$data->id, "is_hot"=>$data->is_hot))',
                    'htmlOptions' => array(
                        'style' => 'text-align: center',
                    ),
                ),
        		array(
                    'class' => 'CLinkColumn',
                    'header'=>Yii::t('BackEnd','Status'),
                    'labelExpression' => 'Common::getStatus($data->status)',
                    'urlExpression' => 'Yii::app()->createUrl("article/publish", array("id"=>$data->id, "status"=>$data->status))',
                    'htmlOptions' => array(
                        'style' => 'text-align: center',
                    ),
                ),
        		array(
        			'class'=>'CButtonColumn',
                    'header'=>Yii::t('BackEnd','Options'),
                    'viewButtonOptions'=>array(
                        'style'=>'display:none',
                    ),
                    'updateButtonLabel'=>Yii::t('BackEnd','Edit'),
                    'updateButtonImageUrl'=>Yii::app()->request->baseUrl.'/css/backend/images/edit.png',
                    'updateButtonOptions'=>array(
                        'style'=>'margin-right:5px',
                    ),
                    'deleteButtonLabel'=>Yii::t('BackEnd','Delete'),
                    'deleteButtonImageUrl'=>Yii::app()->request->baseUrl.'/css/backend/images/remove.png',
                    'deleteConfirmation'=>"js:'".Yii::t('BackEnd','Do you want to delete?')."'",
        		),
                array(
                    'class'=>'CCheckBoxColumn',
                    'id'=>'chk',
                    'selectableRows'=>40,
                ),
        	),
        )); ?>
        
        <script>
            function reloadGrid(data) {
                $.fn.yiiGridView.update('article-grid');
            }
        </script>
        <?php
            echo CHtml::ajaxSubmitButton(Yii::t('BackEnd','Delete'),array('article/ajaxdelete'),
                array('success'=>'reloadGrid'),
                array('class'=>'button', 'style'=>'float: right;margin-left:10px', 'confirm'=>Yii::t('BackEnd','Do you want to delete?')));
            echo CHtml::link(Yii::t('BackEnd','Create'), array('article/create'), array('class'=>'button','style'=>'float: right;height:26px')); 
        ?>
        <?php $this->endWidget(); ?>
        <div style="clear: both; margin-bottom: 5px;"></div>
    </div>
</section>
<!-- End Content -->